package com.sicheng.lc.周赛.分类.前缀和or差分数组;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/28 10:07
 */
public class 统计可以提取的工件 {
    //https://leetcode.cn/problems/count-artifacts-that-can-be-extracted/
    public int digArtifacts(int n, int[][] artifacts, int[][] dig) {
        boolean[][] map = new boolean[n][n];
        for (int[] p : dig) {
            map[p[0]][p[1]] = true;
        }
        int res = 0;
        for (int[] artifact : artifacts) {
            int l1 = artifact[0];
            int r1 = artifact[1];
            int l2 = artifact[2];
            int r2 = artifact[3];
            if (l1 == l2) {
                int i = r1;
                for (; i <= r2; i++) {
                    if (!map[l1][i])
                        break;
                }
                if (i > r2) res++;
            } else if (r1 == r2) {
                int i = l1;
                for (; i <= l2; i++) {
                    if (!map[i][r1])
                        break;
                }
                if (i > l2) res++;
            } else if (map[l1][r1] && map[l2][r2] && map[l1][r1 + 1] && map[l1 + 1][r1]) {
                res++;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        统计可以提取的工件 s = new 统计可以提取的工件();
        int n = 2;
        int[][] a = {{0, 0, 0, 0}, {0, 1, 1, 1}}, b = {{0, 0}, {0, 1}};

        System.out.println(s.digArtifacts(2, a, b));
    }

}
